﻿using BSChuangXu.API.Read.Appicant.Commend.RoleCommend;
using BSChuangXu.Domain.User;
using BSChuangXu.ErrorCode;
using BSChuangXu.Infrastructure.Interface;
using MediatR;

namespace BSChuangXu.API.Read.Appicant.CommendHandel.RoleCommandHandler
{
    /// <summary>
    /// [部门id]批量查询用户名称
    /// </summary>
    public class GetDepIdUserCommandHandler : IRequestHandler<GetDepIdUserCommend, APIResult<List<UserModel>>>
    {
        private readonly IBaseRepository<UserModel> userRepos;

        public GetDepIdUserCommandHandler(IBaseRepository<UserModel> userRepos)
        {
            this.userRepos = userRepos;
        }
        /// <summary>
        /// [部门id]批量查询用户名称
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public Task<APIResult<List<UserModel>>> Handle(GetDepIdUserCommend request, CancellationToken cancellationToken)
        {
            APIResult<List<UserModel>> result = new APIResult<List<UserModel>>();
            var list = userRepos.GetAll().Result.Where(x => request.DepId.Contains(x.DepId.ToString()));
            if (list != null)
            {
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.data = list.ToList();
            }
            else
            {
                result.Code = APIEnum.查询失败;
                result.Msg = APIEnum.查询失败.ToString();
            }
            return Task.FromResult(result);
        }
    }
}
